package com.auxgroup.hr.front.service.process.impl;

import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import com.auxgroup.hr.front.dao.domain.PsCWfPersonVw;
import com.auxgroup.hr.front.dao.repository.PsCWfPersonVwRepository;
import com.auxgroup.hr.front.service.process.WfPersonVwService;

/** 
 * @author wangchangyun
 * @version 创建时间：180601 
 * 社保公积金service
 */
@Service("wfPersonVwService")
public class WfPersonVwServiceImpl implements WfPersonVwService {
	@Autowired
	private PsCWfPersonVwRepository PsCWfPersonVwRepository;


	@Override
	public PsCWfPersonVw getWfPersonVw(String id) {
		return PsCWfPersonVwRepository.findOne(id);
	}
	
	@Override
	public List<PsCWfPersonVw> getAll(String queryValue) {
		StringBuilder queryStr = new StringBuilder(queryValue);
		queryStr.insert(0, "%");
		queryStr.append("%");
		Specification<PsCWfPersonVw> speci = new Specification<PsCWfPersonVw>() {
			@Override
			public Predicate toPredicate(Root<PsCWfPersonVw> root,CriteriaQuery<?> query, CriteriaBuilder builder) {
				Predicate namelike = builder.like(root.get("nameDisplay"), queryStr.toString());
				return  builder.and(namelike);
			}
		};
		PageRequest pageReq = new PageRequest(0, 50);
		Page<PsCWfPersonVw> result = PsCWfPersonVwRepository.findAll(speci,pageReq);
		return result.getContent();
	}
}
